package com.itheima.reggie.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders) {

        ordersService.submit(orders);

        return R.success("订单提交成功");
    }

    @GetMapping ("/page") //分页信息         //订单号模糊查询            时间查询的参数
    public R<Page> page(int page, int pageSize, Long number, String beginTime, String endTime) {
        //分页查询构造器
        Page<Orders> pageInfo = new Page<>(page, pageSize);
        //条件查询
        LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<>();
        //订单号模糊查询
        wrapper.like(number != null, Orders::getNumber, number);
        //根据时间区间查询
        wrapper.between(beginTime != null && endTime != null, Orders::getOrderTime, beginTime, endTime);
        ordersService.page(pageInfo, wrapper);
        return R.success(pageInfo);

    }
}
